/**
 * Copyright (C) T-Systems International, 2013-2014
 *
 * The copyright of the computer program herein is the property of
 * T-Systems International. The program may be used and/or copied
 * only with the written permission of T-Systems International or in
 * accordance with the terms and conditions stipulated in the
 * agreement/contract under which the program has been supplied.
 *
 * $Author$
 * $Date$
 * $Rev$
 */
package com.tsystems.migdb.batch.listener;

import com.tsystems.migdb.batch.Person;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.StringUtils;
import org.springframework.batch.core.listener.ItemListenerSupport;

import java.util.List;

@Log4j2
public class MigdbItemListener extends ItemListenerSupport<Person, Person> {

    @Override
    public void afterRead(Person item) {
        log.debug("an item has been read:\n" + item);
    }

    @Override
    public void afterProcess(Person item, Person result) {
        log.debug(item + " has been converted to " + result);
    }

    @Override
    public void onProcessError(Person item, Exception e) {
        log.error("an error occurred during processing an item:\n" + item, e);
    }

    @Override
    public void afterWrite(List<? extends Person> items) {
        log.debug("the items have been written:\n" + StringUtils.join(items, "\n"));
    }

    @Override
    public void onWriteError(Exception e, List<? extends Person> items) {
        log.error("an error occurred during writing the items:\n" + StringUtils.join(items, "\n"), e);
    }

}